<template>
  <div>
    <div class="btns">
      <el-form size="small" inline style="text-align: center">
        <el-form-item label="名称">
          <el-input v-model="param.name"></el-input>
        </el-form-item>
        <el-form-item>
       <el-button size="small"  round type="primary" icon="el-icon-search" plain  @click="loadCategory">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-button size="mini" type="info"   plain style="float:right"  @click="toAddHandler">新增</el-button>
 
    </div>
    <!-- /按钮 --> 
    <!-- 表格 -->
    <el-table size="small" :data="category">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column label="名称" prop="name" align="center"></el-table-column>
      <el-table-column label="描述" prop="description" align="center"></el-table-column>
      <el-table-column label="数量" prop="no" align="center"></el-table-column>
      <el-table-column label="parent_id" prop="parentId" align="center"></el-table-column>
         <el-table-column label="操作" width="200" align="center">
        <!-- 定制-插槽 -->
        <template slot-scope="scope">  
          <el-button-group>  
      <el-button type="primary" plain size="mini"  icon="el-icon-arrow-left" @click="editHandler(scope.row)">编辑</el-button>
      <el-button type="danger"  plain size="mini"  @click="deleteHandler(scope.row)">删除<i class="el-icon-arrow-right el-icon--right" ></i></el-button>
         </el-button-group>
        </template>
      </el-table-column>
    </el-table>
<!-- /表格 -->
</div>
</template>

<script>
import {del, get,post} from '@/utils/request'
export default { 
     data(){
    return {
      param:{},
      category:[]
    }
  },

//方法表示一个具体的操作，主要书写业务逻辑；
   methods:{
          editHandler(row){
       this.$router.push({path:"/article/categoryCreate",query:row,});
    },
         // 删除事件处理函数
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://39.106.31.187:8888/category/deleteById";
        del(url,{ id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadCategory();
        });
      });
    },

    // 跳转
    toAddHandler(){
      this.$router.push("/article/categoryCreate")
    },
    // 查询后台中的应用信息
    loadCategory(){
      let url = "http://39.106.31.187:8888/category/query"
      get(url,this.param).then(resp => {
        this.category = resp.data;
      });
    },
      goBack(){
      this.$router.back();
    }
  },

  // 页面加载的时候会执行的方法
  created(){
    this.loadCategory();
    console.log(this.$router);
  },
}
</script>
<style scoped>
.btns {
  margin-bottom: .5em;
}
</style>
